/*
 * AuctionDay class.
 * 
 * @author Kevin Smith.
 */

package model;

import java.util.Calendar;

/**
 * AuctionDay class.
 * 
 * @author Kevin Smith.
 */
public class AuctionDay {

	/** Unchangeable date */
	private final Calendar my_date;

	/** An auction occurring this date */
	private Auction my_auction1 = null;

	/** An auction occurring this date */
	private Auction my_auction2 = null;

	/** Full if both auctions have values */
	private boolean is_full = false;
	
	/** Empty if no auctions */
	public boolean is_empty = true;

	/**
	 * Create a new AuctionDay
	 * 
	 * @pre the_date != null
	 * 
	 * @param the_date Base Calendar object
	 * @param i how many days to add (or subtract, or zero)
	 */
	public AuctionDay(final Calendar the_date, final int i) {
		my_date = the_date;
		my_date.add(Calendar.DATE, i);
	}

	/**
	 * Returns the Auction 1
	 * 
	 * @return the my_auction1
	 */
	public Auction getAuction1() {
		return my_auction1;
	}

	/**
	 * Adds a new auction to the day.
	 * Sets the AuctionDay to full if both auctions have values.
	 * 
	 * @param auc Auction to be added
	 */
	public void addAuction(Auction auc) {
		if (this.my_auction1 == null) {
			this.my_auction1 = auc;
			this.is_empty = false;
		} else {
			this.my_auction2 = auc;
			this.setFull(true);
		}
	}

	/**
	 * Returns the Auction 2
	 * 
	 * @return the my_auction2
	 */
	public Auction getAuction2() {
		return my_auction2;
	}

	/**
	 * Returns the date.
	 * 
	 * @return the my_date
	 */
	public Calendar getDate() {
		return my_date;
	}

	/**
	 * Returns the is_full.
	 * 
	 * @return the is_full
	 */
	public boolean isFull() {
		return is_full;
	}

	/**
	 * Returns the is_full to FALSE or TRUE
	 * according to parameter passed.
	 * 
	 * @param is_full the is_full to set
	 */
	public void setFull(boolean is_full) {
		this.is_full = true;
	}

	/**
	 * Cancel an auction on this date
	 * 
	 * @param cancel_me the auction to be canceled
	 */
	public void cancelAuction(Auction cancel_me) {
		if (cancel_me == my_auction1) {
			this.my_auction1 = null;
			this.is_full = false;
		} else if (cancel_me == my_auction2) {
			this.my_auction2 = null;
			this.is_full = false;
		}
	}
	
	/**
	 * Returns a String representation of the Auction Day object.
	 * 
	 * @return a String representation.
	 */
	public String toString() {
		String my_auction1Test = "test1";
		String my_auction2Test = "test2";
		return "auction1=" + my_auction1Test + ", auction2="
		+ my_auction2Test ;
	}
}
